﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.ProcessModuleDomain
{
    public class ProcessModuleServiceFactory : IProcessModuleServiceFactory
    {

        //private readonly IServiceProvider _services;
        private readonly IEnumerable<IProcessMuduleService> _processMuduleServices;

        public ProcessModuleServiceFactory(IEnumerable<IProcessMuduleService> processMuduleServices)
        {
            _processMuduleServices = processMuduleServices;
        }

        public IProcessMuduleService Create( string processModuleType)
        {
            //var type = Assembly.GetAssembly(typeof(IProcessMuduleService)).GetType($"Zocono.WCS.Domain.ProcessModuleDomain.{processModuleType}");
            //var instance = _provider.GetService(typeof(ProcessModulePlanarService));
            //var instance = _services.GetRequiredService(typeof(ProcessModulePlanarService));
            //return instance as IProcessMuduleService;

            var instance = _processMuduleServices.SingleOrDefault(s => s.GetType().Name == processModuleType);
            return instance;
        }
    }
}
